package com.wk.springboot.jdbs;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname ArrayTest
 * @Description 对数组的操作
 * @Date 2020/8/28 9:39
 * @Author by weikai
 */
public class ArrayTest {

  private Integer[] paramArray;

  /**
   * 1
   * 1    1
   * 2    1
   * 1    2    1    1
   * 1    1    1    2    2    1
   * 3    1    2    2    1    1
   * 1    3    1    1    2    2    2   1
   * 1 1 1 3 2 1 3 2 1 1
   */

  public static void main(String[] args) {

    Integer[] integers = new Integer[]{1  ,  3  ,  1  ,  1  ,  2  ,  2  ,  2  , 1};
//    Integer[] integers = new Integer[]{3   , 1   , 2  ,  2  ,  1    ,1};
//    Integer[] integers = new Integer[]{1   , 1   , 1  ,  2  ,  2    ,1};
    Object[] objects = generarteArray(integers);
    for(int i = 0; i < objects.length; i++){
      System.out.print(objects[i]+" ");
    }
  }

  private static Object[] generarteArray(Integer[] params){

    Integer[] paramArray = params;

    List list = new ArrayList<>();
    Integer tmp = 0;
    Integer count = 0;
    for(int i = 0;i < params.length; i++){

      if(i == 0){
        tmp = params[i];
      }

      if(tmp.equals(params[i])){
        count ++ ;
      }else {
        list.add(count);
        list.add(tmp);
        count = 1;
        tmp = params[i];
      }
    }
    list.add(count);
    list.add(tmp);
    return list.toArray();
  }

}
